package com.lemon.ashe.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;

/**
 * @program: SpringBootZoo
 * @author: Mr.Young
 * @create: 2021/4/6 23:24
 **/
@Service
public class HystrixService {

    public String hello(Integer id) {
        return "HystrixService 线程池：" + Thread.currentThread().getName() + " id is: " + id;
    }

    @HystrixCommand(fallbackMethod = "hello_timeout_back",
            commandProperties = {
                    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000")
            })
    public String hello_timeout(Integer id) {
        if (id == 99) {
            throw new NullPointerException();
        }
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "HystrixService timeout 线程池：" + Thread.currentThread().getName() + " id is: " + id;
    }

    public String hello_timeout_back(Integer id) {
        return "系统繁忙，请稍后再试 线程池：" + Thread.currentThread().getName() + " id is: " + id;
    }
}
